#include "../Header Files/Window.h"

Window::Window(void)
{
	hWnd = NULL;
	db_graphic = NULL;
	db_buffer = NULL;
}


Window::~Window(void)
{	
	

	if(db_buffer){
		//delete db_buffer;
		//db_buffer = NULL;
	}
	if(db_graphic){
		//delete db_graphic;
		//db_graphic = NULL;
	}
	


	if(hWnd){
		DestroyWindow(hWnd);
		hWnd = NULL;
	}
}

void Window::initToPaint()
{
	RECT cr;
	GetClientRect(hWnd, &cr);

	if(db_buffer){
		delete db_buffer;
		db_buffer = NULL;
	}
	db_buffer = new Bitmap(cr.right - cr.left, cr.bottom - cr.top);

	if(db_graphic){
		delete db_graphic;
		db_graphic = NULL;
	}
	db_graphic = new Graphics(db_buffer);

}

HWND Window::gethWnd()
{
	return hWnd;
}

void Window::show()
{
	ShowWindow (hWnd,SW_NORMAL);
}

void Window::setIcon(WORD icon_id)
{
	SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(getHInstance(), MAKEINTRESOURCE(icon_id)));
}

void Window::setColor(COLORREF color)
{
	if(hWnd){
		HDC hDC = GetDC(hWnd);
		SetBkColor(hDC, color);
		ReleaseDC(hWnd, hDC);
		SendMessage(hWnd, WM_PAINT, NULL, NULL);
	}
}

void Window::setSize(int width, int height)
{
	//SendMessage(hWnd, WM_SIZE, NULL, LOWORD(width) + HIWORD(height));
	SetWindowPos(hWnd, NULL, 0, 0, width, height, SWP_NOMOVE);
}

void Window::setPos(int x, int y)
{
	//SendMessage(hWnd, WM_MOVE, NULL, LOWORD(x) + HIWORD(y));
	SetWindowPos(hWnd, NULL, x, y, 0, 0, SWP_NOSIZE);
}

void Window::maximalize()
{
	//SendMessage(hWnd, WM_MOVE, NULL, LOWORD(x) + HIWORD(y));
	ShowWindow(hWnd, SW_MAXIMIZE);
}



DWORD WINAPI Window::redraw()
{
	//SendMessage(hWnd, WM_PAINT, 0, 0);
	InvalidateRect(hWnd,NULL,TRUE);
	return 0;
}